{extend name="public/base" /}
{block name="pjax_container"}
<?php
    $titleTypeName = '课程编辑/添加';
?>

<script>
    function p_model(e, val='', img=''){
        var num = e.parents(".col-sm-7").find("img").length;
        if(!img) img = "__STATIC__/default.png";
        var html = '<div class="p_model"><input class="form-control" required="required" name="model[]" value="'+val+'" placeholder="课程型号名称" style="width: 50%;display: inline;margin-right: 10px;margin-bottom:10px; ">' +
            '<input class="form-control" type="hidden" name="img'+num+'" value="'+img+'"/>' +
            '<img onclick="alertImage(this)" src="'+img+'" style="width:37px;height:37px;"/>' +
            '<button type="button" class="layui-btn" id="img'+num+'"><i class="layui-icon">&#xe67c;</i>上传图片</button> ' +
            '<button class="layui-btn del">删除</button></div>';
        e.parents('.col-sm-7').append(html);

        layui.use('upload', function(){
            var upload = layui.upload;

            var nameDom = "img"+num;
            //执行实例
            upload.render({
                elem: "#"+nameDom //绑定元素
                ,url: "{:url('File/store')}" //上传接口
                ,accept:"images"
                ,exts:"png|jpg|jpeg"
                ,done: function(res){
                    //上传完毕回调
                    $('#'+nameDom).parent().find('input[name*='+nameDom+']').val(res.data.saveName);
                    $('#'+nameDom).parent().find('img').attr('src', res.data.saveName);
                    // $('#'+nameDom).parent().find('a').text("点击预览");
                }
            });
        });
    }
</script>

<style>
    tr>th,
    td {
        text-align: center;
    }



    .content-header>.breadcrumb>li {
        color: #999;
    }

    .content-header>.breadcrumb>.active {
        color: #666;
    }

    .content-header {
        height: 51px;

    }

    .btn-primary {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 5px 10px;
    }

    .box-primary {
        border-top-color: #ecf0f5 !important;
        border-top-width: 16px;

    }

    .btn-primary:hover {
        background-color: #1890FF;
        color: #fff;
        border: none;
        opacity: .9;
        border-radius: 6px !important;
    }

    .delete-one {
        background-color: ff4141 !important;
        margin-left: 15px;
        border-radius: 6px;
    }

    .sreachs {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 7px 15px;
    }

    .input-group {
        display: flex;
        flex-wrap: wrap;
    }

    .sreachs:hover {
        background-color: #1890FF;
        color: #fff;
        border: none;
        opacity: .8;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 7px 15px;
    }

    .form-group>label {
        height: 100%;
        line-height: 30px;
        margin-left: 10px;
    }

    .form-group>input {
        border: none;
        height: 100%;
        border-bottom: 1px solid #ccc;
    }

    .nav-tabs-custom {
        margin-top: 16px;
    }
</style>
<section class="content-header">
  
    <ol class="breadcrumb">
        <li>商城管理</li>
        <li>课程列表</li>
        <li class="active">{$titleTypeName}</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" method="POST" action="/{$Think.MODULE_NAME}/{$Think.CONTROLLER_NAME}/{$Think.ACTION_NAME}" onsubmit="return false" >
                <input type="hidden" name="id" value="{$info.id|default=0}" />
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="pull-right"><a href="javascript:history.back(-1)" class="btn btn-sm" style="padding:10px 2px;"><i class="fa fa-list"></i> 返回</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab1">
                            {include file="form/input" title="课程名称" name="name"/}

                            <div class="form-group">
                                <label class="col-sm-2 control-label">课程型号</label>
                                {if condition="empty($model)"}
                                <div class="col-sm-7">
                                    <button class="layui-btn add" style="display: block">添加</button>
                                </div>
                                {else:}
                                <div class="col-sm-7">
                                    <button class="layui-btn add add2" style="display: block">添加</button>

                                    {foreach name="$model" item="vo" }
                                    <script>
                                        var e = $('.add2');
                                        p_model(e,"{$vo.model_name}","{$vo.img}");
                                    </script>
                                    {/foreach}
                                </div>
                                {/if}
                            </div>

                            {include file="form/input_time" title="课程时间" name="course_time"/}
                            {include file="form/layui_image" title="封面图" name="image" data="isset($info['image']) ? $info['image'] : ''"/}
                            {include file="form/input" title="产品单价" name="price"/}
                            {include file="form/input" title="销量" name="sales"/}
                            {include file="form/input" title="库存" name="inventory"/}
                            {include file="form/input" title="排序" name="sort"/}
                            {include file="form/textarea" title="内容" name="content" data="isset($info['content']) ? $info['content'] : ''"/}
                            <div class="form-group">
                                <label class="col-sm-2 control-label">状态</label>
                                <div class="col-sm-7">
                                    <label class="checkbox-inline"><input type="radio" name="status" value="1" {if condition="!isset($info['status']) || $info['status']==1"}checked{/if} class="minimal"> 开启</label>
                                    <label class="checkbox-inline"><input type="radio" name="status" value="0" {if condition="isset($info['status']) && $info['status']==0"}checked{/if} class="minimal"> 关闭</label>
                                </div>
                            </div>
                        </div>

                    </div>


                    <div class="box-footer">
                        <div class="col-sm-2"></div>
                        <div class="col-sm-7">
                            <div class="btn-group pull-right">
                                <button type="submit" class="btn btn-info pull-right submits" data-loading-text="&lt;i class='fa fa-spinner fa-spin '&gt;&lt;/i&gt; 提交">提交</button>
                            </div>
                        </div>
                    </div>

                </div>
            </form>
        </div>
    </div>
</section>
<script type="application/javascript">
    $(document).ready(function () {
        /*ajax页面加载icheck，有该控件的页面才需要*/
        $(".select2").select2({language:"zh-CN"});

    })

    $('.add').on('click',function () {
        p_model($(this));
    });

    function alertImage(e){
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            maxWidth:700,
            maxHeight:700,
            shadeClose: true,
            skin: '',
            content: '<img style="max-width: 1000px; max-height: 1000px" src="' + e.src + '" />'
        });
    }

    $(document).on("click", ".del",function () {
        var a = this;
        $(a).parents('.p_model').remove();
    });
</script>
{/block}
